#!/usr/bin/env bash
# Load functions and variables
jbt=$(cat /usr/bin/.jbtype)
jbtype=$(echo $jbt)

export NEWT_COLORS='root=,black
border=white,black
title=white,black
roottext=red,black
window=red,black
textbox=white,black
button=black,green
compactbutton=white,black
listbox=white,black
actlistbox=black,white
actsellistbox=black,green
checkbox=green,black
actcheckbox=black,green
'

whiptail_height="$(($(tput lines) - 6))"
whiptail_width="$(($(tput cols) - 20))"

if [ "$jbtype" = "Rootless" ]; then
  OPTIONS="$(whiptail --separate-output --nocancel --ok-button "Select" --title "palera1n options" --checklist \
  "Press spacebar to select option, and enter to complete" 15 54 5 \
  "1" "Verbose" ON \
  "2" "Safe Mode" OFF \
  "3" "Revert Install" OFF \
  "4" "Serial" OFF \
  "5" "Debug" OFF 3>&1 1>&2 2>&3)"
  if [ $? = 0 ]; then
      output=""
      for OPTION in $OPTIONS; do
          case $OPTION in
              "1") output1="-V";;
              "2") output2="-s";;
              "3") output3="--force-revert";;
              "4") output4="-e 'serial=3'";;
              "5") output5="-v";;
          esac
      done
      echo "$output1 $output2 $output3 $output4 $output5" > /usr/bin/.args
      /usr/bin/palera1n_menu
  else
      echo "Cancelled"
  fi
elif [ "$jbtype" = "Rootful" ]; then
  OPTIONS="$(whiptail --separate-output --nocancel --ok-button "Select" --title "palera1n options" --checklist \
  "Press spacebar to select option, and enter to complete" 15 54 5 \
  "1" "Create FakeFS" OFF \
  "2" "Create BindFS" OFF \
  "3" "Clean FakeFS" OFF \
  "4" "Verbose" ON \
  "5" "Safe Mode" OFF \
  "6" "Revert Install" OFF \
  "7" "Serial" OFF \
  "8" "Debug" OFF 3>&1 1>&2 2>&3)"
  if [ $? = 0 ]; then
      output=""
      for OPTION in $OPTIONS; do
          case $OPTION in
              "1") output1="-c";;
              "2") output2="-B";;
              "3") output3="-C";;
              "4") output4="-V";;
              "5") output5="-s";;
              "6") output6="--force-revert";;
              "7") output7="-e 'serial=3'";;
              "8") output8="-v";;
          esac
      done
      echo "$output1 $output2 $output3 $output4 $output5 $output6 $output7 $output8" > /usr/bin/.args
      /usr/bin/palera1n_menu
  else
      echo "Cancelled"
  fi
fi
